﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using UnitTestUtils.UI;
using System.Windows.Controls;
using System.Windows;
using AppToolkit.WPF.Utils;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;

namespace AppToolkit.WPF.Tests.Controls
{
    [TestFixture]
    public class ImageButtonTests
    {
        UIHost _host;
        Button _target;

        #region Setup / Teardown
        [SetUp]
        public void Setup()
        {
            _target = new Button();
            _target.Width = 200;
            _target.Height =200;
            
            
            
            _host = UIHost.Create(_target);
        }

        [TearDown]
        public void Dispose()
        {
            _target = null;
            _host = null;
            UnitTestUtils.UI.UITestHelper.CleanupDispatcher();
        }
        #endregion

        [Test, RequiresSTA]
        public void InteractiveTest_real_Exception()
        {
            _host.Show();

            ResourceDictionary rd = new ResourceDictionary();
            rd.Source = PackUriHelper.From(typeof(PackUriHelper), "Controls/ImageButtonStyle.xaml");
            _host.Window.Resources.MergedDictionaries.Add(rd);

            _target.Style = (Style)_host.Window.Resources["ImageButtonStyle"];

            var img = new Image();
            img.Width = 190;

            img.Source = BitmapHelper.CreateTestImage();
            _target.Content = img;

            DispatcherTimer timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(2);
            timer.Tick += (s, a) =>
                {
                    _target.IsEnabled = !_target.IsEnabled;
                };
            timer.Start();

            _host.WaitForClose();
        }
    }
}
